$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/linepassword/list',
        datatype: "json",
        colModel: [
			{ label: '设备号', name: 'devicesn', index: 'devicesn', width: 80 }, 			
			{ label: '二维码', name: 'qcodeid', index: 'qcodeid', width: 80 },
            { label: '所属代理商', name: 'agentid', index: 'agentid', width: 80,formatter: function(cellvalue, options, rowdata) {
                    var shopName = "" ;
                    if(rowdata.agentid!=null && rowdata.agentid!=""){
                        $.ajax({
                            type: "POST",
                            async:false,
                            url: baseURL + "sys/user/info/"+rowdata.agentid,
                            success: function(r){
                                if (null == r.user) {
                                    shopName="";
                                } else {
                                    shopName = r.user.username;
                                }
                            }
                        });
                    }

                    return shopName;
                }
            },
            { label: '分配代理商时间', name: 'agenttime', index: 'agenttime', width: 80 },
            { label: '所属业务员', name: 'salesid', index: 'salesid', width: 80,formatter: function(cellvalue, options, rowdata) {
                    var shopName = "" ;
                    if(rowdata.salesid!=null && rowdata.salesid!="") {
                        $.ajax({
                            type: "POST",
                            async: false,
                            url: baseURL + "sys/user/info/" + rowdata.salesid,
                            success: function (r) {
                                if (null == r.user) {
                                    shopName = "";
                                } else {
                                    shopName = r.user.username;
                                }
                            }
                        });
                    }
                    return shopName;
                }
            },
			{ label: '分配业务员时间', name: 'salestime', index: 'salestime', width: 80 },
            { label: '商户', name: 'merchant', index: 'merchant', width: 80,formatter: function(cellvalue, options, rowdata) {
                    var shopName ="";
                    if(rowdata.merchant!=null && rowdata.merchant!="") {
                        $.ajax({
                            type: "POST",
                            async: false,
                            url: baseURL + "sys/merchant/infoByUserid/" + rowdata.merchant,
                            success: function (r) {
                                if (null == r.merchant) {
                                    shopName = "";
                                } else {
                                    shopName = r.merchant.name;
                                }
                            }
                        });
                    }
                    return shopName;
                }
            },
            { label: '分配商户时间', name: 'merchanttime', index: 'merchanttime', width: 80 },
            { label: '操作', name: 'sy', width: 100,align:'center',formatter: function(cellvalue, options, rowdata) {
                    return "<a style='cursor:pointer;' class='btn btn-primary'" +
                        "onclick=vm.update("+rowdata.id+",'"+rowdata.devicesn+"',"+rowdata.agentid+","+rowdata.salesid+","+rowdata.merchant+")>" +
                        "关联下级</a>";
                }}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            devicesn: null,
            qcodeid: null,
            agentid: null,
            salesid: null,
            merchant: null
        },
        qcx: {
            shopName: null,
            shopPhone: null,
            status: null
        },
        qxz: {
            shopName: null,
            shopPhone: null,
            status: null
        },
        ywyxz: {
            shopName: null,
            shopPhone: null,
            status: null
        },
        qcxsh: {
            name: null,
            district: null,
            status: null
        },
        qcxshxz: {
            name: null,
            district: null,
            status: null
        },
		showList: true,
		title: null,
        agentshopbus: {},
		linePassword: {
            agentidcx:null,
            merchantcx:null,
            salesid:null,
            busname:null
        }
	},
    agentshopbus: {},
    linePassword: {
        agentidcx:null,
        merchantcx:null,
        salesid:null,
        busname:null
    },
	methods: {
		query: function () {
			vm.reload();
		},
        queryAdminCX: function () {
            vm.reloadAgentCX();
        },
        queryMerchantCX: function () {
            vm.reloadMerchantCX();
        },
        queryAdminXZ: function () {
            vm.reloadAgentXZ();
        },
        querySaleXZ: function () {
            vm.reloadAgentXZ();
        },
        queryMerchantXZ: function () {
            vm.reloadMerchantXZ();
        },
		add: function(){
            vm.getBusAgent();
			vm.showList = false;
			vm.title = "新增";
			vm.linePassword = {
                salesid:null,
                busName:null
            };
			$("#fileInput").hide();
            $("#textInput").show();
            $("#btnSaveUpload").hide();
            $("#btnSaveOrUpdate").show();
		},
        addAll: function(){
            vm.getBusAgent();
            vm.showList = false;
            vm.title = "新增";
            vm.linePassword = {
                salesid:null,
                busName:null
            };
            $("#fileInput").show();
            $("#textInput").hide();
            $("#btnSaveUpload").show();
            $("#btnSaveOrUpdate").hide();
        },
		update: function (id,devicesn,agentid,salesid,merchant) {
		    var role = "";
            $.ajax({
                type: "POST",
                url: baseURL + "sys/role/getRoleLoginUser",
                async: false,
                success: function(r){
                    if(r.role!=null){
                        role = r.role.roleName;
                    }
                }
            });

            vm.linePassword.id = id;
            vm.linePassword.devicesn = devicesn;
            //vm.getBusAgent();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";

            $("#fileInput").hide();
            $("#textInput").show();
            $("#btnSaveUpload").hide();
            $("#btnSaveOrUpdate").show();

            if(role!=""&&role.indexOf("代理商") != -1){
                $("#ssywy").show();
                $("#ssdls").hide();
                $("#sssh").hide();
                vm.showSale(salesid);
            }else if(role!=""&&role.indexOf("业务员") != -1){
                $("#ssywy").hide();
                $("#ssdls").hide();
                $("#sssh").show();
                vm.showMerchant(merchant);
            }else if(role!=""&&role.indexOf("商户") != -1){

            }else{
                $("#ssywy").hide();
                $("#ssdls").show();
                $("#sssh").hide();
                vm.showAgent(agentid);
            }
            //vm.getInfo(id)
		},

        showAgent:function (agentid) {
            $("#agentids").val("");
		    if(agentid!=null&&agentid!=""){
                $.ajax({
                    type: "POST",
                    async:false,
                    url: baseURL + "sys/user/info/"+agentid,
                    success: function(r1){
                        if(r1.user!=null){
                            $("#agentids").val(r1.user.username);
                            vm.linePassword.agentid = r1.user.userId;

                        }

                    }
                });
            }

        },
        showSale:function (salesid) {
            $("#sales").val("");
		    if(salesid!=null&&salesid!=""){
                //业务
                $.ajax({
                    type: "POST",
                    async:false,
                    url: baseURL + "sys/user/info/"+salesid,
                    success: function(r1){
                        if(r1.user!=null){
                            vm.linePassword.salesid = r1.user.userId;
                            $("#sales").val(r1.user.username);
                        }

                    }
                });
            }

        },
        showMerchant:function (merchant) {
		    if(merchant!=null&&merchant!=""){
                //商户
                $.ajax({
                    type: "POST",
                    async:false,
                    url: baseURL + "sys/merchant/infoByUserid/"+merchant,
                    success: function(r1){
                        $("#merchants").val(r1.merchant.name);
                        vm.linePassword.merchant=r.merchant.userid;
                    }
                });
            }

        },
        downFormwork :function () {
            var lock = false;
            layer.confirm('确定要下载二维码编号模板？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                if(!lock) {
                    lock = true;
                    $.ajax({
                        type: "POST",
                        url: baseURL + "sys/linepassword/formwork",
                        contentType: "application/json",
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                                vm.reload();
                            }else{
                                layer.alert(r.msg);
                            }
                        }
                    });
                }
                layer.alert("C:\\Users\\Administrator\\Desktop/二维码模板.xls成功,请到桌面查找！")
                vm.reload();
            }, function(){

            });
        },
        timeStamp2String:function(time){
            var datetime = new Date();
            datetime.setTime(time);
            var year = datetime.getFullYear();
            var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
            var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
            var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
            var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
            var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
            return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
        },
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.linePassword.id == null ? "sys/linepassword/save" : "sys/linepassword/update";
                var displaydls =$('#ssdls').css('display');
                var displayywy =$('#ssywy').css('display');
                var displaysh =$('#sssh').css('display');
                if(displaydls == 'block'){
                    vm.linePassword.agenttime = vm.timeStamp2String(new Date());
                }
                if(displayywy == 'block'){
                    vm.linePassword.salestime = vm.timeStamp2String(new Date());
                }
                if(displaysh == 'block'){
                    vm.linePassword.merchanttime = vm.timeStamp2String(new Date());
                }
                console.log(displaydls+"========="+displayywy+'============'+displaysh)
                console.log(vm.linePassword)
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.linePassword),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                            vm.reload();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
        //上传文件
        saveUpload: function (event) {
            $('#btnSaveUpload').button('loading').delay(1000).queue(function() {
                var crowd_file = $('#files')[0].files[0];
                var formData = new FormData();

                formData.append("files",crowd_file);
                formData.append("agentids", vm.linePassword.agentid);
                formData.append("salesid", vm.linePassword.salesid);
                formData.append("merchants", vm.linePassword.merchant);
                $.ajax({
                    type: "POST",
                    url: baseURL + "sys/linepassword/saveUpload",
                    data: formData,
                    processData : false, // 使数据不做处理
                    contentType : false, // 不要设置Content-Type请求头
                    success: function(r){
                        if(r.code === 0){
                            layer.msg("操作成功", {icon: 1});
                            $('#btnSaveUpload').button('reset');
                            $('#btnSaveUpload').dequeue();
                            vm.reload();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveUpload').button('reset');
                            $('#btnSaveUpload').dequeue();
                        }
                    }
                });
            });
        },
		del: function (event) {
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "sys/linepassword/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
        addAdminCX: function () {
            $("#jqGridAddCX").jqGrid({
                url: baseURL + 'sys/agent/list',
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '代理商名称', name: 'shopName', index: 'SHOP_NAME', width: 80 },
                    { label: '代理商手机', name: 'shopPhone', index: 'SHOP_PHONE', width: 80 },
                    // { label: '代理模式 0 购买设备 1 投放设备', name: 'shopType', index: 'SHOP_TYPE', width: 80 },
                    { label: '代理模式', name: 'shopType', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">购买设备</span>' :
                                '<span class="label label-success">投放设备</span>';
                        }},
                    { label: '代理商上级', name: 'shopParent', index: 'SHOP_PARENT', width: 80 },
                    { label: '佣金百分比', name: 'shopRatio', index: 'SHOP_RATIO', width: 80 },
                    // { label: '0 可打开所属机柜 1 不可打开', name: 'isopen', index: 'isOPEN', width: 80 },
                    { label: '可打开所属机柜', name: 'isopen', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">是</span>' :
                                '<span class="label label-success">否</span>';
                        }},
                    // { label: '所属系统', name: 'sysSystem', index: 'SYS_SYSTEM', width: 80 },
                    // { label: '状态 0 正常 1 禁用', name: 'status', index: 'STATUS', width: 80 },
                    { label: '状态', name: 'status', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">正常</span>' :
                                '<span class="label label-success">异常</span>';
                        }},
                    // { label: '备注', name: 'remarks', index: 'REMARKS', width: 80 },
                    // { label: '创建时间', name: 'createdTime', index: 'CREATED_TIME', width: 80 },
                    // { label: '登录密码', name: 'loginPassword', index: 'LOGIN_PASSWORD', width: 80 }
                    { label: '操作', name: 'sy', width: 70,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseCX("+ rowdata.id +")'>" +
                                "<span class='btn btn-primary'>选择</span></a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerCX",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddCX").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalCX').modal();
        },
        shopChooseCX:function (id) {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/agent/info/"+id,
                success: function(r){
                    $("#agentParentCX").html("");
                    $("#agentParentCX").append(r.agent.shopName);
                    vm.linePassword.agentidcx=r.agent.id;
                }
            });
            $('#myModalCX').modal("hide");

        },
        addMerchant: function () {
            $("#jqGridMerchant").jqGrid({
                url: baseURL + 'sys/merchant/list',
                datatype: "json",
                colModel: [
                    { label: '商户名称', name: 'name', index: 'name', width: 80 },
                    // { label: '所属代理商', name: 'agent', index: 'agent', width: 80 },
                    // { label: '所属业务员', name: 'businessid', index: 'businessId', width: 80 },
                    { label: '所属代理商', name: 'agent', index: 'agent', width: 80,formatter: function(cellvalue, options, rowdata) {
                            var shopName ;
                            $.ajax({
                                type: "POST",
                                async:false,
                                url: baseURL + "sys/agent/info/"+rowdata.agent,
                                success: function(r){
                                    if (null == r.agent) {
                                        shopName="";
                                    } else {
                                        shopName = r.agent.shopName;
                                    }
                                }
                            });
                            return shopName;
                        }
                    },
                    // { label: '所属业务员', name: 'businessid', index: 'businessId', width: 80 },
                    { label: '所属业务员', name: 'businessid', index: 'businessid', width: 80,formatter: function(cellvalue, options, rowdata) {
                            var shopName ;
                            $.ajax({
                                type: "POST",
                                async:false,
                                url: baseURL + "sys/agentshopbus/infobus/"+rowdata.businessId,
                                success: function(r){
                                    if (null == r.agentShopBus) {
                                        shopName="";
                                    } else {
                                        shopName = r.agentShopBus.busName;
                                    }
                                }
                            });
                            return shopName;
                        }
                    },
                    { label: '业务员佣金百分比', name: 'businessRatio', index: 'business_RATIO', width: 80 },
                    { label: '省', name: 'province', index: 'PROVINCE', width: 80 },
                    { label: '市', name: 'city', index: 'CITY', width: 80 },
                    { label: '区', name: 'district', index: 'DISTRICT', width: 80 },
                    { label: '详细地址', name: 'address', index: 'ADDRESS', width: 80 },
                    { label: '状态', name: 'status', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">正常</span>' :
                                '<span class="label label-success">禁止</span>';
                        }},
                    { label: '操作', name: 'sy', width: 70,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseMerchant("+ rowdata.id +")'>" +
                                "<span class='btn btn-primary'>选择</span></a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerMerchant",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridMerchant").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalMerchant').modal();
        },
        shopChooseMerchant:function (id) {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/merchant/info/"+id,
                success: function(r){
                    $("#merchant").html("");
                    $("#merchant").append(r.merchant.name);
                    vm.linePassword.merchantcx=r.merchant.id;
                }
            });
            $('#myModalMerchant').modal("hide");

        },
        //新增代理商
        addAdminXZ: function () {
            $("#jqGridAddXZ").jqGrid({
                url: baseURL + 'sys/agent/list',
                datatype: "json",
                colModel: [
                    { label: 'id', name: 'userId', index: 'userId', width: 50, key: true,hidden:true },
                    { label: '代理商名称', name: 'username', index: 'username', width: 150 },
                    { label: '代理商手机', name: 'mobile', index: 'mobile', width: 150 },
                    { label: '佣金百分比', name: 'commission', index: 'commission', width: 150 },
                    { label: '状态', name: 'status', width: 110, formatter: function(value, options, row){
                            return value === 1 ?
                                '<span class="label label-success">正常</span>' :
                                '<span class="label label-danger">异常</span>';
                        }},
                    { label: '操作', name: 'sy', width: 100,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseXZ("+ rowdata.userId +")'>" +
                                "<span class='btn btn-primary'>选择</span></a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerXZ",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddXZ").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            $('#myModalXZ').modal();
        },
        shopChooseXZ:function (id) {
            $("#agentids").val("");
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/user/info/"+id,
                success: function(r){
                    $("#agentids").val(r.user.username);

                    vm.linePassword.agentid=r.user.userId;
                }
            });
            $('#myModalXZ').modal("hide");

        },
        //新增业务员
        addYWY: function () {
            $("#jqGridAddYWY").jqGrid({
                url: baseURL + 'sys/agent/businesslist',
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '业务员名称', name: 'username', index: 'username', width: 130 },
                    { label: '业务员手机', name: 'mobile', index: 'mobile', width: 120 },
                    { label: '所属代理商', name: 'agent', index: 'agent', width: 120 },
                    { label: '佣金百分比', name: 'commission', index: 'commission', width: 110 },
                    { label: '状态', name: 'status', width: 80, formatter: function(value, options, row){
                            return value === 1 ?
                                '<span class="label label-success">正常</span>' :
                                '<span class="label label-danger">异常</span>';
                        }},
                    { label: '操作', name: 'sy', width: 90,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.saleChooseXZ("+ rowdata.userId +")'>" +
                                "<span class='btn btn-primary'>选择</span></a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerYWY",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddYWY").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            $('#myModalYWY').modal();
        },

        saleChooseXZ:function (id) {
            $("#sales").val("");
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/user/info/"+id,
                success: function(r){
                    $("#sales").val(r.user.username);

                    vm.linePassword.salesid=r.user.userId;
                }
            });
            $('#myModalYWY').modal("hide");

        },

        //新增商户
        addMerchantXZ: function () {
            $("#jqGridMerchantXZ").jqGrid({
                url: baseURL + 'sys/merchant/merchantlist',
                datatype: "json",
                colModel: [
                    { label: '商户名称', name: 'name', index: 'name', width: 140 },
                    { label: '商户负责人', name: 'username', index: 'username', width: 140 },
                    { label: '商户电话', name: 'shopPhone', index: 'shopPhone', width: 140},
                    { label: '分佣比例', name: 'businessRatio', index: 'businessRatio', width: 120},
                    { label: '地址', name: 'address', index: 'address',  width: 140 },
                    { label: '操作', name: 'sy', width: 90,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseMerchantXZ("+ rowdata.id +")'>" +
                                "<span class='btn btn-primary'>选择</span></a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerMerchantXZ",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridMerchantXZ").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalMerchantXZ').modal();
        },
        shopChooseMerchantXZ:function (id) {
            $("#merchants").val("");
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/merchant/info/"+id,
                success: function(r){
                    console.log(r.merchant.name+"=============="+r.merchant.userid);
                    $("#merchants").val(r.merchant.name);

                    vm.linePassword.merchant=r.merchant.userid;

                }
            });
            $('#myModalMerchantXZ').modal("hide");

        },
		getInfo: function(id){
			$.get(baseURL + "sys/linepassword/info/"+id, function(r){


                vm.linePassword = r.linePassword;
            });
		},
        getBusAgent: function () {
            $.ajax({
                type: "POST",
                url: baseURL + "sys/agentshopbus/getUsers",
                success: function (r) {
                    console.log(r);
                    if (r.code == 0) {
                        vm.agentshopbus = r.data;
                    } else {
                        layer.alert(r.msg);
                    }
                }
            });
            console.log(vm);
        },
        setUsername: function (id) {
            for (var i = 0; i < vm.agentshopbus.length; i++) {
                if (id == vm.agentshopbus[i].id) {
                    vm.linePassword.busname = vm.agentshopbus[i].busName;
                }
            }
            console.log(vm);
        },
		reload: function (event) {
			vm.showList = true;
            // vm.q.agentid = $("#agentParentCX").text();
            vm.q.agentid = vm.linePassword.agentidcx;
            vm.q.salesid = $("#salesid").text();    //业务员
            // vm.q.merchant = $("#merchant").text();
            vm.q.merchant=vm.linePassword.merchantcx;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData: {'devicesn': vm.q.devicesn,
                    'qcodeid': vm.q.qcodeid,
                    'salesid': vm.q.salesid,
                    'merchant': vm.q.merchant,
                    'agentid': vm.q.agentid
                },
                page:page
            }).trigger("reloadGrid");
		},
        reloadAgentCX: function (event) {
            vm.showList = true;
            var page = $("#jqGridAddCX").jqGrid('getGridParam','page');
            $("#jqGridAddCX").jqGrid('setGridParam',{
                postData: {'status': vm.qcx.status,
                    'shopName': vm.qcx.shopName,
                    'shopPhone': vm.qcx.shopPhone
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadMerchantCX: function (event) {
            vm.showList = true;
            var page = $("#jqGridMerchant").jqGrid('getGridParam','page');
            $("#jqGridMerchant").jqGrid('setGridParam',{
                postData: {'status': vm.qcxsh.status,
                    'name': vm.qcxsh.name,
                    'district': vm.qcxsh.district
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadAgentXZ: function (event) {
            var page = $("#jqGridAddXZ").jqGrid('getGridParam','page');//myModalXZ
            $("#jqGridAddXZ").jqGrid('setGridParam',{
                postData: {'status': vm.qxz.status,
                    'username': vm.qxz.shopName,
                    'mobile': vm.qxz.shopPhone
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadSaleXZ: function (event) {
            var page = $("#jqGridAddYWY").jqGrid('getGridParam','page');//myModalXZ
            $("#jqGridAddYWY").jqGrid('setGridParam',{
                postData: {'status': vm.ywyxz.status,
                    'username': vm.ywyxz.shopName,
                    'mobile': vm.ywyxz.shopPhone
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadMerchantXZ: function (event) {
            var page = $("#jqGridMerchantXZ").jqGrid('getGridParam','page');
            $("#jqGridMerchantXZ").jqGrid('setGridParam',{
                postData: {'status': vm.qcxshxz.status,
                    'username': vm.qcxshxz.name,
                    'district': vm.qcxshxz.district
                },
                page:page
            }).trigger("reloadGrid");
        }
	}
});